Skip to content

Add additional contextual information to invalid-style-prop warning#4482

Closed
niole wants to merge 13 commits intofacebook:masterfrom
niole:issue4168
Closed

Add additional contextual information to invalid-style-prop warning#4482
niole wants to merge 13 commits intofacebook:masterfrom
niole:issue4168

Conversation

@niole
Copy link
Copy Markdown
Contributor

@niole niole commented Jul 24, 2015

inline style prop error thrown for JSX React elements now names React class that erroring element is a child of. Fixes #4168

@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@niole
Copy link
Copy Markdown
Contributor Author

niole commented Jul 24, 2015

This works in a live setting when inside of a working app.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the style prop of the owner component? This doesn't look right to me. I don't think it's the "style prop of the owner"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the issue as being it would be helpful if the error message
contained the name of the react class that has the render method where the
style prop has bad syntax, which is what that piece of code returns
On Jul 24, 2015 11:03 PM, "Jim" notifications@github.com wrote:

In src/renderers/dom/shared/ReactDOMComponent.js
#4482 (comment):

@@ -263,7 +263,7 @@ function assertValidProps(component, props) {
}
invariant(
props.style == null || typeof props.style === 'object',

  • 'The style prop expects a mapping from style properties to values, ' +
  • 'The style prop of '+component._currentElement._owner._instance.proto.constructor.displayName + ' expects a mapping from style properties to values, ' +

It's the style prop of the owner component? This doesn't look right to me.


Reply to this email directly or view it on GitHub
https://github.com/facebook/react/pull/4482/files#r35480276.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops must have been sleepy when I submitted that. I would change it to say
'check the render method of '+code_snippet

I read the issue as being it would be helpful if the error message
contained the name of the react class that has the render method where the
style prop has bad syntax, which is what that piece of code returns
On Jul 24, 2015 11:03 PM, "Jim" notifications@github.com wrote:

In src/renderers/dom/shared/ReactDOMComponent.js
#4482 (comment):

@@ -263,7 +263,7 @@ function assertValidProps(component, props) {
}
invariant(
props.style == null || typeof props.style === 'object',

  • 'The style prop expects a mapping from style properties to values, ' +
  • 'The style prop of '+component._currentElement._owner._instance.proto.constructor.displayName + ' expects a mapping from style properties to values, ' +

It's the style prop of the owner component? This doesn't look right to me.


Reply to this email directly or view it on GitHub
https://github.com/facebook/react/pull/4482/files#r35480276.

@jimfb jimfb changed the title resolves issue #4168, Add additional contextual information to invalid-style-prop warning Jul 27, 2015
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to have an if-check, because there is no guarantee that _owner isn't null (element could have been created outside of a render method), in which case this will throw.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add %s into the string here, then pass getDecl..() as a 3rd argument.

@niole
Copy link
Copy Markdown
Contributor Author

niole commented Jul 31, 2015

Should I add this prefix to the test and the actual code?
On Jul 31, 2015 10:41 AM, "Niole Nelson" niolenelson@gmail.com wrote:

Cool. I'm on it.
On Jul 31, 2015 10:36 AM, "Paul O’Shannessy" notifications@github.com
wrote:

And yes, you're missing the 'Invariant Violation:' prefix.


Reply to this email directly or view it on GitHub
#4482 (comment).

@jimfb
Copy link
Copy Markdown
Contributor

jimfb commented Jul 31, 2015

@niole No, just the test. The issue is that the actual code adds it automatically when you invoke invariant but the test does not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still have a leading space inside the text which doesn't belong. But do we really need this new sentence? I don't think it really adds anything and with the addendum we'll say to check the render method of a component.

@zpao
Copy link
Copy Markdown
Member

zpao commented Jul 31, 2015

Please run your tests locally before pushing. You can iterate much more quickly that way instead of waiting for travis to tell you there are failures.

@jimfb
Copy link
Copy Markdown
Contributor

jimfb commented Jul 31, 2015

You can run your tests using npm test.

If you read somewhere that you should use npm run jest, be aware that has been removed in favor of npm test.

@niole
Copy link
Copy Markdown
Contributor Author

niole commented Jul 31, 2015

What's up with this eslint-plugin-react-internal and how do I get it?
On Jul 31, 2015 10:58 AM, "Jim" notifications@github.com wrote:

You can run your tests using npm test.

If you read somewhere that you should use npm run jest, be aware that has
been removed in favor of npm test.


Reply to this email directly or view it on GitHub
#4482 (comment).

@zpao
Copy link
Copy Markdown
Member

zpao commented Jul 31, 2015

npm install should do it. You may need to install npm >= 2.0 though for that to work. If you're on npm < 2 you might be able to do npm install ./eslint-rules to pick it up.

@niole
Copy link
Copy Markdown
Contributor Author

niole commented Aug 19, 2015

@zpao @jimfb how does it look.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just leave the beginning of this message as it was. We really just need the addendum.

@zpao
Copy link
Copy Markdown
Member

zpao commented Aug 19, 2015

Sorry for the delay, GitHub doesn't send notifications when there are new / changed commits added.

@niole
Copy link
Copy Markdown
Contributor Author

niole commented Aug 20, 2015

@zpao @jimfb how does it look? I'm also wondering about how to run tests locally. I upgraded npm and everything's installing.

  • I then run npm test and get Cannot find module 'fbjs/scripts/babel/rewrite-requires'.
    babel, which 'couldn't be found', and a lot of failed tests
  • I then upgraded jest to 5.x.
  • Now I have this jsdom 4.x onward only works on io.js, not Node.js™, and what seems like less failed tests

should I use io.js?

@niole
Copy link
Copy Markdown
Contributor Author

niole commented Aug 27, 2015

@zpao @jimfb Does this need work?

zpao added a commit that referenced this pull request Aug 28, 2015
Add additional contextual information to invalid-style-prop warning
@zpao
Copy link
Copy Markdown
Member

zpao commented Aug 28, 2015

I squashed, cleaned up the unrelated changes, and pushed (your commit: 70c07c6, merge: bdc7ce9). Thanks for sticking with it!

@niole
Copy link
Copy Markdown
Contributor Author

niole commented Aug 28, 2015

@zpao Thanks!

On Thu, Aug 27, 2015 at 6:29 PM, Paul O’Shannessy notifications@github.com
wrote:

I squashed, cleaned up the unrelated changes, and pushed (your commit:
70c07c6
70c07c6,
merge: bdc7ce9
bdc7ce9).
Thanks for sticking with it!


Reply to this email directly or view it on GitHub
#4482 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants